.org 0xE646C ; Firepower Increase

Firepower_Increase:

	PUSH 	{R4-R7, LR}	
	SUB 	SP, SP, 4
		
	MOV		R6, 0								; Firepower bonus = 0
	
;-------------------------------------------------------------------------------
	
	LDR 	R4, [Firepower_Increase_1]
	LDR 	R3, [Firepower_Increase_2]
	LDR 	R5, [R4, 0]
	LDR 	R4, [R3, 0]
	
	MOV 	R3, 0x98
	ADD 	R4, R5, R4, LSL 2
	MUL		R5, R0, R3
	LDR 	R4, [R4, 0x48]
	MOV		R7, R2
	ADD 	R0, R4, 0x5000
	LDR 	R0, [R0, 0xA58]
	MOV		R4, R1, LSL 4
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R1, LSL 4
		
	MOV 	R1, CO_Teamwork						; Skill: Teamwork
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped		
	CMP 	R0, 0								; Does CO use that skill?	
	ADDNE 	R6, R6, Stats_Teamwork				; If CO use skill, Partner has more firepower	

;-------------------------------------------------------------------------------	
	
	BL		Skill_Setup_Type_Firepower
	
	MOV 	R1, CO_Synergy						; Skill: Synergy
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Synergy				; If CO use skill, Partner has more firepower	
		
;-------------------------------------------------------------------------------	

	MOV		R0, R7								; R0 = Unit
	
	BL 		Check_Unit_Type
	
	CMP		R0, Unit_Direct_Combat				; Is Unit a Direct?
	BEQ		Skill_Firepower_Direct
	
	CMP		R0, Unit_Indirect_Combat			; Is Unit an Indirect?
	BEQ		Skill_Firepower_Indirect
	
	B		Skill_Firepower_Weather

;-------------------------------------------------------------------------------	

Skill_Firepower_Direct:

	BL		Skill_Setup_Type_Firepower
	
	MOV 	R1, Rank_Bruiser					; Rank: Bruiser
		
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Bruiser				; If CO use skill, more Direct firepower	

;-------------------------------------------------------------------------------	
	
	BL		Skill_Setup_Type_Firepower
	
	MOV 	R1, Rank_Brawler					; Rank: Brawler
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Brawler				; If CO use skill, more Direct firepower	
	
	B		Skill_Firepower_Weather

;-------------------------------------------------------------------------------	

Skill_Firepower_Indirect:

	BL		Skill_Setup_Type_Firepower
	
	MOV 	R1, Rank_Sharpshooter				; Rank: Sharpshooter
		
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Sharpshooter			; If CO use skill, more Indirect firepower	
	
;-------------------------------------------------------------------------------		
	
	BL		Skill_Setup_Type_Firepower
	
	MOV 	R1, Rank_Sniper						; Rank: Sniper
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Sniper				; If CO use skill, more Indirect firepower
	
;-------------------------------------------------------------------------------

Skill_Firepower_Weather:
	
	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R1, [R1, 0]
	LDR 	R0, [R0, 0]
	
	ADD		R0, R1, R0, LSL 2
	LDR		R1, [R0, 0x48]	
	LDR		R0, [R1, 0x1C4]
	LDRB	R0, [R0, 0x3A]
	
	CMP		R0, Snow
	BEQ		Skill_Firepower_Snow				; Is weather snow?
	
	CMP		R0, Rain
	BEQ		Skill_Firepower_Rain				; Is weather rain?
	
	CMP		R0, Sandstorms
	BEQ		Skill_Firepower_Sand				; Is weather sandstorms?
	
	B		Skill_Firepower_Clear

;-------------------------------------------------------------------------------	

Skill_Firepower_Snow:

	BL		Skill_Setup_Type_Attack_Weather
	
	MOV 	R1, Rank_Icebreaker					; Rank: Icebreaker
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Icebreaker			; If CO use skill, more firepower

;-------------------------------------------------------------------------------
	
	BL		Skill_Setup_Type_Firepower
	
	MOV 	R1, CO_Firepower_Snow				; Skill: Firepower in Snow
		
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Firepower_Snow		; If CO use skill, more firepower
	
	B		Skill_Firepower_Clear

;-------------------------------------------------------------------------------	

Skill_Firepower_Rain:

	BL		Skill_Setup_Type_Attack_Weather
	
	MOV 	R1, Rank_High_and_Dry				; Rank: High and Dry
	
	BL 		Check_Skills_Equipped				; Check the Skill is equipped	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_High_and_Dry			; If CO use skill, more firepower
	
	B		Skill_Firepower_Clear

;-------------------------------------------------------------------------------	

Skill_Firepower_Sand:

	BL		Skill_Setup_Type_Attack_Weather
	
	MOV 	R1, Rank_Sand_Scorpion				; Rank: Sand Scorpion
		
	BL 		Check_Skills_Equipped				; Check the Skill is equipped
	
	CMP 	R0, 0								; Does CO use that skill?
	ADDNE 	R6, R6, Stats_Sand_Scorpion			; If CO use skill, more firepower

;-------------------------------------------------------------------------------

Skill_Firepower_Clear:
	
	MOV		R0, R6								; Total firepower bonus
	
	ADD		SP, SP, 4	
	POP 	{R4-R7, LR}	
	BX 		LR
	
;-------------------------------------------------------------------------------

Skill_Setup_Type_Firepower:						; Firepower Setup

	LDR 	R1, [Firepower_Increase_1]
	LDR 	R0, [Firepower_Increase_2]
	LDR 	R2, [R1, 0]
	LDR 	R0, [R0, 0]	
	
	ADD		R0, R2, R0, LSL 2
	LDR 	R0, [R0, 0x48]	
	ADD 	R0, R0, 0x5000
	LDR 	R0, [R0, 0xA58]
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BX 		LR
	
;-------------------------------------------------------------------------------

Skill_Setup_Type_Attack_Weather:				; Firepower Weather Setup

	ADD 	R0, R1, 0x5000
	LDR 	R0, [R0, 0xA58]	
	ADD 	R0, R0, R5
	ADD 	R0, R0, 0x74
	ADD		R0, R0, R4
	
	BX 		LR
	
;-------------------------------------------------------------------------------		

	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP
	NOP

;-------------------------------------------------------------------------------	

Firepower_Increase_1:
	.dw Reg1_Skill
	
Firepower_Increase_2:
	.dw Reg2_Skill
	
	

	



